Skip to content

Conversation

@IanDelMar
Copy link
Contributor

The return type of sanitize_term_field() depends on both the $field being sanitised and the $context.

For integer fields

$int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' );

it returns a non-negative integer. The exact constant value cannot be inferred from the input $value, as the passed $values are strings.

For all other fields, the type depends on the $context:

  • 'raw': $value is returned as is, which is handled via the template T; for constant strings, the same constant string is returned.
  • 'attribute'|'edit'|'js': $value is escaped--and may be transformed--using esc_attr(), esc_html(), or esc_js(). Assuming the filters in these functions do not alter the type, the returned type is string, even if $value is a constant string.
  • All other $context values: $value is not escaped but is filtered, with the filter callback documented as returning mixed. Therefore, the default return type of mixed is retained.

@szepeviktor szepeviktor merged commit 8fb9fdc into php-stubs:master Sep 8, 2025
7 checks passed
@IanDelMar IanDelMar deleted the sanitize_term_field branch September 9, 2025 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants